package com.he1618;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.WriteApiBlocking;
import com.influxdb.client.domain.WritePrecision;

import java.time.Instant;

public class WriteApp {

    public static void main(String[] args) throws InterruptedException {
        InfluxDBClient client = client();
        System.out.println(client.version());

        for (int i = 0; i < 50000; i++) {
            Mem mem = new Mem();
            mem.host = "host1";
            mem.used_percent = Math.random()*10000;
            mem.score= (int) (Math.random()*1000);
            mem.age= (int) (Math.random()*1000);
            mem.time = Instant.now();
            String bucket = "ada";
            String org = "ada";

            WriteApiBlocking writeApi =  client.getWriteApiBlocking();
            writeApi.writeMeasurement(bucket, org, WritePrecision.NS, mem);
            Thread.sleep(100);
        }

    }
    public static InfluxDBClient client(){

        String token = "J_b9Esev3GqZtbFLiA_bo6rvye7aaxssC8MiO99KtXgQmfd-VZyNKo3LvoMWfIfNiEZyLncr1UObY2YrArlTbg==";


        return InfluxDBClientFactory.create("http://192.168.3.108:8086", token.toCharArray());


    }
}
